<?php
/**
 * author: JiangJun
 * CreateTime:2021/8/11 11:06 上午
 */

use Aws\Exception\AwsException;
use Aws\Sqs\SqsClient;

require './vendor/autoload.php';

$client = new SqsClient([
    'region' => 'us-west-2',
    'version' => '2012-11-05'
]);

$queueUrl = "https://sqs.us-west-2.amazonaws.com/863376839233/love";
//使用这个方法，可以获取和上面一样的url
$queueUrl=$client->getQueueUrl(['QueueName'=>'love'])->get('QueueUrl');

$params = [
    'DelaySeconds' => 10,//设置放入队列的延迟时间
    'MessageAttributes' => [//消息的属性
        "Title" => [//属性名
            'DataType' => "String",//属性类型
            'StringValue' => "The Hitchhiker's Guide to the Galaxy"//属性值
        ],
        "Author" => [
            'DataType' => "String",
            'StringValue' => "Douglas Adams."
        ],
        "WeeksOn" => [
            'DataType' => "Number",
            'StringValue' => "6"
        ]
    ],
    //只有下面两个参数，是必填的
    'MessageBody' => "Information about current NY Times fiction bestseller for week of 12/11/2016.",
    'QueueUrl' => $queueUrl
];

try {
    $result = $client->sendMessage($params);//发送消息
    var_dump($result);
} catch (AwsException $e) {
    // output error message if fails
    error_log($e->getMessage());
}